C# 按钮->数据库->DataGridView

来源:百度知道 编辑:UC知道 时间:2024/06/16 01:33:04
触发按钮的CLick事件时,怎么样才能在DataGridView控件上显示保存在数据库(SQL)中表里的信息,
就是:按钮和数据库之间是怎么联系。也就是写出按钮CLick事件的代码,为了在DataGridView中显示数据库(SQL)中表里的信息
private void button15_Click(object sender, EventArgs e)
{
??????????……
}
写的好的话有奖励分

private void button15_Click(object sender, EventArgs e)
{
string sql=select* from 表 where 列;///构建查询语句,查询数据库.

Dataset ds= new dataset(sql);///读出数据库内容

Gridview.DataSource=ds;//将值赋给控件.

Gridview.DataBind();//将数据绑定.

}

protected void dgSendList_BuildDataSource(object sender, System.EventArgs e)
{
this.dgSendList.DataSource = this.DataSource;
}

protected override void LoadData()
{
this.dgSendList.InvokeBuildDataSource();
this.dgSendList.BuildData();
}

protected void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
//
// CODEGEN: 绑定页面列表数据。
//
this.LoadData();
}
}

先用SQL语句从数据库中读取你需要显示的数据,然后放到Datatable里面,再写代码
DataGridV